package es.udc.cameraar2;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class MainActivity extends Activity {

	Context mContext;

	private Camera camera;
	
	//prueba

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// setContentView(R.layout.activity_main);

		mContext = this;
		CameraPreview mPreview;

		if (CameraFunctions.checkCameraHardware(mContext)) {
			int numCams = CameraFunctions.getNumberOfCameras();
			if (numCams > 1) {
				int i = 0;
				Toast.makeText(this, "Getting information from camera " + i,
						Toast.LENGTH_LONG).show();
			
				
				camera = CameraFunctions.getCameraInstance(i);
				Panel panel = new Panel(this);
				// Create our Preview view and set it as the content of our
				// activity.
				mPreview = new CameraPreview(this, camera, panel);

				setContentView(mPreview);
				addContentView(panel, new LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

			}
			// If there is only one camera
			else {
				camera = CameraFunctions.getCameraInstance();
				// Create our Preview view and set it as the content of our
				// activity.
				/*
				 * mPreview = new CameraPreview(this, camera); FrameLayout
				 * preview = (FrameLayout) findViewById(R.id.camera_preview);
				 * preview.addView(mPreview);
				 */
			}

		} else {
			Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
					.show();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	protected void onPause() {
		if (camera != null) {
			camera.release();
			camera = null;
		}
		super.onPause();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return false;

	}
}
